module.exports = {
	data() {
		return {
			disableList: false,
			listLoading: true,
			list: [],
			page: 1,
			rows: 10,
			pageNum: 1,
			total: 0,
			currentIndex: -1
		}
	},
	computed: {
		currentDataInfo() {
			return this.currentIndex >= 0 ? this.list[this.currentIndex] : {}
		}
	},
	methods: {
		listBtnUpdateData(data) {
			for (let key in data) {
				this[key] = data[key]
			}
		},
		listBtnUpdateRow(data) {
			for (let key in data) {
				this.list[data.index][key] = data[key]
			}
		},
		getList(isFirst, param) {
			param = param || {}
			this.listLoading = true;
			if (isFirst) {
				this.list = []
				this.page = 1;
			}
			if (Object.keys(param).length > 0)
				this.query = Object.assign(this.query, param)
			let query = {
				pageNum: this.page,
				pageSize: this.rows,
				...this.query,
			};
			this.request('post', this.queryUrl, query).then(res => {
				this.setList(res)
			})
		},
		setList(res) {
			if (res.page) {
				this.pageNum = res.page.totalPage || 0;
				this.total = res.page.totalCount || 0;
				res = res.page.list
				if (this.getListSuccessBefore)
					this.getListSuccessBefore(res)
				res.forEach(el=>{
					this.list.push(el)
				})
				if (this.getListSuccess)
					this.getListSuccess(res)
			}
			this.listLoading = false
		},
		doOnRechBottom() {
			if(this.page >= this.pageNum || this.listLoading){
			    return;
			}
			this.page++;
			this.getList(false);
		},
	},
	onReachBottom(){
	    this.doOnRechBottom()
	},
	onLoad() {
		if (!this.disableList)
			this.getList(true)
	}
}